
package com.shop.cloud.mall.api.controller;

import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.portal.annotation.ApiLogin;
import com.shop.cloud.mall.api.service.UserRecordService;
import com.shop.cloud.common.portal.util.ThirdSessionHolder;
import com.shop.cloud.mall.common.entity.UserRecord;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 用户消费记录API
 *
 * @author
 * @date 2021-04-22 11:18:16
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/userrecord")
@Tag(description = "userrecord", name = "用户消费记录API")
public class UserRecordController {

    private final UserRecordService userRecordService;

    /**
     * 用户消费记录查询
     * @return R
     */
    @Operation(summary = "用户消费记录查询")
    @GetMapping
	@ApiLogin
    public R getById() {
		UserRecord userRecord = userRecordService.getById(ThirdSessionHolder.getUserId());
		if(userRecord == null){
			userRecord = new UserRecord();
			userRecord.setTotalAmount(BigDecimal.ZERO);
			userRecord.setTotalOrder(0);
		}
        return R.ok(userRecord);
    }

}
